using System;
using System.Web.UI.WebControls;
using System.Web.UI;
using System.Collections.Generic;
using System.Reflection;

using SBPweb.RouTorrent.Business;

namespace SBPweb.RouTorrent.Host.Controls
{
	public partial class TorrentInfos : System.Web.UI.UserControl
	{

		//private Services.Manage mManage = new SBPweb.RouTorrent.Host.Services.Manage();

		protected void Page_Load(object sender, EventArgs e)
		{
			BindData();
		}

		protected override void OnPreRender(EventArgs e)
		{
			base.OnPreRender(e);
            /*
			string script = string.Format("setProgressDivProperties('{0}', '{1}');", upPanel.ClientID, upProgress.ClientID);

			this.Page.ClientScript.RegisterStartupScript(typeof(SBPweb.Controls.Web.UpdateProgress), upProgress.ID, script, true);
            */
		}

		private void BindData()
		{
			//BindData(mManage.ReadTorrentInfos());
		}

		private void BindData(List<object> source)
		{
            /*
			dgTorrents.DataSource = source;
			dgTorrents.DataBind();
            */
		}

		protected void dgTorrents_SortCommand(object source, DataGridSortCommandEventArgs e)
		{
			//List<TorrentInfo> list = mManage.ReadTorrentInfos();

			//list.Sort(new TorrentInfoComparer(e.SortExpression, SortDirection.Ascending));
			//BindData(list);
		}

		protected void dgTorrents_PageIndexChanged(object source, DataGridPageChangedEventArgs e)
		{
			//dgTorrents.CurrentPageIndex = e.NewPageIndex;
			BindData();
		}

        /*
		public class TorrentInfoComparer : IComparer<TorrentInfo>
		{
			private string mExpression;
			private int mSgn;
			private PropertyInfo mPI;
			private MethodInfo mMI;

			public TorrentInfoComparer(string expression, SortDirection direction)
			{
				mExpression = expression;
				mSgn = (direction == SortDirection.Ascending) ? 1 : -1;
			}

			#region IComparer<TorrentInfo> Members

			public int Compare(TorrentInfo x, TorrentInfo y)
			{
				if (x == null && y == null)
				{
					return 0;
				}

				if (mPI == null)
				{
					mPI = x.GetType().GetProperty(mExpression);
				}
				if (mMI == null)
				{
					mMI = mPI.PropertyType.GetMethod("CompareTo", new Type[] { mPI.PropertyType });
				}

				object oX = mPI.GetValue(x, null);
				object oY = mPI.GetValue(y, null);

				if (oX == null && oY != null)
				{
					return -1 * mSgn;
				}
				if (oY == null && oX != null)
				{
					return 1 * mSgn;
				}

				if (oX == null && oY == null)
				{
					return 0;
				}

				return Convert.ToInt32(mMI.Invoke(oX, new object[] { oY })) * mSgn;
			}

			#endregion
		}
        */
	}
}